
cd ""

use "coups_data_clean_final_yearly.dta", clear


xtset leaderspell t_leader

gen post_t = 0 if f2.coup_fail == 1
bys leaderspell: replace post_t = l.post_t + 1 if l.post_t != . & l.post_t < 6
order post_t

gen post_t_colpus = 0 if f2.colpus_fail == 1
bys leaderspell: replace post_t_colpus = l.post_t_colpus + 1 if l.post_t != . & l.post_t_colpus < 6
order post_t_colpus

egen decade = cut(year), at(1950 1960 1970 1980 1990 2000 2011)

******************************************************
** 	Main leaderspell models, PT lagged 1 year
****************************************************** 


// Immediately after a coup:
xtreg latent_personalism l.post_fail if post_t!=., fe cl(leaderspell)
xtreg latent_personalism l.post_fail lgdppc growth oil_new milex if post_t!=., fe cl(leaderspell)
	
// General model before and after a coup:
xtreg latent_personalism l.post_fail, fe cl(leaderspell)
xtreg latent_personalism l.post_fail t_leader lgdppc growth oil_new milex i.year, fe cl(leaderspell)

// General model before and after a coup, only if failed coup happened:
xtreg latent_personalism l.post_fail if max_failed_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail t_leader lgdppc growth oil_new milex i.year if max_failed_coups>0, fe cl(leaderspell)
 
// Immediately after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail if post_t!=. & max_any_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail lgdppc growth oil_new milex if post_t!=. & max_any_coups>0, fe cl(leaderspell)

// General model before and after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail if max_any_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail t_leader lgdppc growth oil_new milex i.year if max_any_coups>0, fe cl(leaderspell)
 

* Mixed effects with regime fixed effects 
xtreg latent_personalism l.post_fail lgdppc growth oil_new milex i.id if post_t!=., cl(leaderspell)

* Mixed effects with country fixed effects 
xtreg latent_personalism l.post_fail lgdppc growth oil_new milex i.ccode if post_t!=., cl(leaderspell)
 

******************************************************
** 	Autorregressive robust PT lagged 1 year
****************************************************** 

** Main leaderspell models, lagged 1 year and autorregressive

// Immediately after a coup:
xtreg latent_personalism l.post_fail l.latent_personalism if post_t!=., fe cl(leaderspell)

// General model before and after a coup:
xtreg latent_personalism l.post_fail l.latent_personalism i.year, fe cl(leaderspell)

// General model before and after a coup, only if failed coup happened:
xtreg latent_personalism l.post_fail l.latent_personalism i.year if max_failed_coups>0, fe cl(leaderspell)

// Immediately after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail l.latent_personalism if post_t!=. & max_any_coups>0, fe cl(leaderspell)

// General model before and after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail l.latent_personalism i.year if max_any_coups>0, fe cl(leaderspell)


******************************************************
** 	Main leaderspell models, COLPUS lagged 1 year
****************************************************** 


// Immediately after a coup:
xtreg latent_personalism l.post_fail_colpus if post_t_colpus!=., fe cl(leaderspell)
xtreg latent_personalism l.post_fail_colpus lgdppc growth oil_new milex if post_t_colpus!=., fe cl(leaderspell)
	
// General model before and after a coup:
xtreg latent_personalism l.post_fail_colpus, fe cl(leaderspell)
xtreg latent_personalism l.post_fail_colpus t_leader lgdppc growth oil_new milex i.year, fe cl(leaderspell)

// General model before and after a coup, only if failed coup happened:
xtreg latent_personalism l.post_fail_colpus if max_failed_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail_colpus t_leader lgdppc growth oil_new milex i.year if max_failed_coups>0, fe cl(leaderspell)
 
// Immediately after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail_colpus if post_t_colpus!=. & max_any_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail_colpus lgdppc growth oil_new milex if post_t_colpus!=. & max_any_coups>0, fe cl(leaderspell)

// General model before and after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail_colpus if max_any_coups>0, fe cl(leaderspell)
xtreg latent_personalism l.post_fail_colpus t_leader lgdppc growth oil_new milex i.year if max_any_coups>0, fe cl(leaderspell)
 

* Mixed effects with regime fixed effects 
xtreg latent_personalism l.post_fail_colpus lgdppc growth oil_new milex i.id if post_t_colpus!=., cl(leaderspell)

* Mixed effects with country fixed effects 
xtreg latent_personalism l.post_fail_colpus lgdppc growth oil_new milex i.ccode if post_t_colpus!=., cl(leaderspell)



******************************************************
** 	Autorregressive robust COLPUS lagged 1 year
****************************************************** 

** Main leaderspell models, lagged 1 year and autorregressive

// Immediately after a coup:
xtreg latent_personalism l.post_fail_colpus l.latent_personalism if post_t_colpus!=., fe cl(leaderspell)

// General model before and after a coup:
xtreg latent_personalism l.post_fail_colpus l.latent_personalism i.year, fe cl(leaderspell)

// General model before and after a coup, only if failed coup happened:
xtreg latent_personalism l.post_fail_colpus l.latent_personalism i.year if max_failed_coups>0, fe cl(leaderspell)

// Immediately after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail_colpus l.latent_personalism if post_t_colpus!=. & max_any_coups>0, fe cl(leaderspell)

// General model before and after a coup, only if ANY coup happened:
xtreg latent_personalism l.post_fail_colpus l.latent_personalism i.year if max_any_coups>0, fe cl(leaderspell)






























** Main leaderspell models, lagged 1 year

xtreg latent_personalism l.post_fail if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l.post_fail, fe cl(leaderspell)

xtreg latent_personalism l.post_fail t oil_new milex i.year if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l.post_fail t oil_new milex i.year, fe cl(leaderspell)

** Main leaderspell models, lagged 1 year and autorregressive

xtreg latent_personalism l.post_fail l.latent_personalism if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l.post_fail l.latent_personalism, fe cl(leaderspell)

xtreg latent_personalism l.post_fail l.latent_personalism oil_new milex if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l.post_fail l.latent_personalism oil_new milex i.year, fe cl(leaderspell)


** Leaderspell models, lagged 2 years

xtreg latent_personalism l2.post_fail if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l2.post_fail, fe cl(leaderspell)

xtreg latent_personalism l2.post_fail t oil_new milex i.year if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l2.post_fail t oil_new milex i.year, fe cl(leaderspell)


** Leaderspell models, lagged 2 years and autorregressive

xtreg latent_personalism l2.post_fail l2.latent_personalism if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l2.post_fail l2.latent_personalism, fe cl(leaderspell)

xtreg latent_personalism l2.post_fail l2.latent_personalism oil_new milex if post_t!=., fe cl(leaderspell)

xtreg latent_personalism l2.post_fail l2.latent_personalism oil_new milex i.year, fe cl(leaderspell)


* Mixed effects with regime fixed effects 
xtreg latent_personalism l1.post_fail l1.latent_personalism oil_new milex i.id if post_t!=., cl(leaderspell)

* Mixed effects with country fixed effects 
xtreg latent_personalism l1.post_fail l1.latent_personalism oil_new milex i.ccode if post_t!=., cl(leaderspell)


* Mixed effects with regime fixed effects 
xtreg latent_personalism l2.post_fail l2.latent_personalism oil_new milex i.id if post_t!=., cl(leaderspell)

* Mixed effects with country fixed effects 
xtreg latent_personalism l2.post_fail l2.latent_personalism oil_new milex i.ccode if post_t!=., cl(leaderspell)


